<?php
$time = time();
$date_before = date("Y-m-d H:i:s",time());
$str = <<<EOT
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>micuer.com在线工具合集,md5解密加密,url加密解密,时间戳转换,base64加密解密等</title>
	<style>
	#app{
	width: 800px;
	height: auto;
	margin: 0 auto;
	}
	table{
	width: 100%;
	}
	input{
	width: 95%;
	}
</style>
</head>
<body>
	<div id="app">
	    <h5>MD5加密解密</h5>
		<table>
			<tr>
				<td>
					<input name="md5_before" v-model="md5_before" @keyup.enter="EnMd5" type="text" placeholder="欲加密字符串">
				</td>
				<td>
					<input name="md5_after" v-model="md5_after" @keyup.enter="DeMd5" type="text" placeholder="加密后">
				</td>
			</tr>
			<tr>
				<td>
					<button @click="EnMd5()">加密></button>
				</td>
				<td>
					<button @click="DeMd5()"><解密</button>
				</td>
			</tr>
		</table>
		<hr>
		<h5>Url加密解密</h5>
		<table>
			<tr>
				<td>
					<input name="url_before" v-model="url_before" @keyup.enter="Enurl" type="text" placeholder="欲加密字符串">
				</td>
				<td>
					<input name="url_after" v-model="url_after" @keyup.enter="Deurl" type="text" placeholder="加密后">
				</td>
			</tr>
			<tr>
				<td>
					<button @click="Enurl()">加密></button>
				</td>
				<td>
					<button @click="Deurl()"><解密</button>
				</td>
			</tr>
		</table>
		
		<hr>
		<h5>时间转换</h5>
		<table>
			<tr>
				<td>
					<input name="date_before" v-model="date_before" @keyup.enter="Endate" type="text" placeholder="欲加密字符串">
				</td>
				<td>
					<input name="date_after" v-model="date_after" @keyup.enter="Dedate" type="text" placeholder="加密后">
				</td>
			</tr>
			<tr>
				<td>
					<button @click="Endate()">加密></button>
				</td>
				<td>
					<button @click="Dedate()"><解密</button>
				</td>
			</tr>
		</table>
</div>
<script src="./js/vue.js"></script>
<script src="./js/jquery.min.js"></script>
<script>
	var app = new Vue({
		el: '#app',
		data:{
			md5_before:''
			,md5_after:''
			,url_before:''
			,url_after:''
			,date_before:"{$time}"
			,date_after:"{$date_before}"
		},
		methods:{
			EnMd5:function(){
				var data = {
					md5_before:this.md5_before
					,md5_after:this.md5_after
					,fun:'enmd5'
				};
				var _self = this;
				$.post("",data,function(e){
				    e = JSON.parse(e);
					if(e.code == 200){
					    _self.md5_after = e.data.md5_after;
					}
					console.log(e)
				})
			}
			,DeMd5:function(){
				var data = {
					md5_before:this.md5_before
					,md5_after:this.md5_after
					,fun:'demd5'
				};
				var _self = this;
				$.post("",data,function(e){
				    e = JSON.parse(e);
					if(e.code == 200){
					    _self.md5_before = e.data.md5_before;
					}
					console.log(e)
				})
			},
			Enurl:function(){
				var data = {
					url_before:this.url_before
					,url_after:this.url_after
					,fun:'enurl'
				};
				var _self = this;
				$.post("",data,function(e){
				    e = JSON.parse(e);
					if(e.code == 200){
					    _self.url_after = e.data.url_after;
					}
					console.log(e)
				})
			}
			,Deurl:function(){
				var data = {
					url_before:this.url_before
					,url_after:this.url_after
					,fun:'deurl'
				};
				var _self = this;
				$.post("",data,function(e){
				    e = JSON.parse(e);
					if(e.code == 200){
					    _self.url_before = e.data.url_before;
					}
					console.log(e)
				})
			}
			,Endate:function(){
				var data = {
					date_before:this.date_before
					,date_after:this.date_after
					,fun:'endate'
				};
				var _self = this;
				$.post("",data,function(e){
				    e = JSON.parse(e);
					if(e.code == 200){
					    _self.date_after = e.data.date_after;
					}
					console.log(e)
				})
			}
			,Dedate:function(){
				var data = {
					date_before:this.date_before
					,date_after:this.date_after
					,fun:'dedate'
				};
				var _self = this;
				$.post("",data,function(e){
				    e = JSON.parse(e);
					if(e.code == 200){
					    _self.date_before = e.data.date_before;
					}
					console.log(e)
				})
			}
		}
	})
	
</script>
</body>
</html>
EOT;
function p($d){
    echo "<pre>";
    print_r($d);
    echo "</pre>";
}


function GetData(){
	$data = $_POST;
	return $data;
}

$data = GetData();
switch ($data["fun"]){
    case 'enmd5':
        enmd5();
        break;
    case 'enurl':
        enurl();
        break;
    case 'deurl':
        deurl();
        break;
    case 'endate':
        endate();
        break;
    case 'dedate':
        dedate();
        break;
    default:
        BuildHtml($str);
        break;
}

function enmd5(){
	$data = GetData();
	$data["md5_after"] = md5($data["md5_before"]);
	 returnJson(200,"成功",$data);
}

function demd5(){
    $data = GetData();
    $data["md5_after"] = md5($data["md5_before"]);
    returnJson(400,"成功",$data);
}

function enurl(){
    $data = GetData();
    $data["url_after"] = urlencode($data["url_before"]);
    returnJson(200,"成功",$data);
}

function deurl(){
    $data = GetData();
    $data["url_before"] = urldecode($data["url_after"]);
    returnJson(200,"成功",$data);
}

function endate(){
    $data = GetData();
    $data["date_after"] = date('Y-m-d H:i:s',$data["date_before"]);
    returnJson(200,"成功",$data);
}

function dedate(){
    $data = GetData();
    $data["date_before"] = strtotime($data["date_after"]);
    returnJson(200,"成功",$data);
}

function BuildHtml($str){
    echo $str;exit();
}


